{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "        <script type=\"text/javascript\">\n",
       "        window.PlotlyConfig = {MathJaxConfig: 'local'};\n",
       "        if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n",
       "        if (typeof require !== 'undefined') {\n",
       "        require.undef(\"plotly\");\n",
       "        requirejs.config({\n",
       "            paths: {\n",
       "                'plotly': ['https://cdn.plot.ly/plotly-latest.min']\n",
       "            }\n",
       "        });\n",
       "        require(['plotly'], function(Plotly) {\n",
       "            window._Plotly = Plotly;\n",
       "        });\n",
       "        }\n",
       "        </script>\n",
       "        "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import plotly\n",
    "import plotly.graph_objs as go\n",
    "import numpy as np\n",
    "plotly.offline.init_notebook_mode(connected=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Basic Box Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "linkText": "Export to plot.ly",
        "plotlyServerURL": "https://plot.ly",
        "showLink": false
       },
       "data": [
        {
         "type": "box",
         "uid": "5670fa7c-595e-49f6-b0bb-078dd333754d",
         "y": [
          -0.44215510218052356,
          -1.962751938763073,
          -1.5955035733628005,
          -2.3925031703948116,
          -0.7578744719890991,
          -1.442432564380551,
          -1.7231288113182066,
          -1.0926302184245615,
          -2.3611279465481214,
          -1.7151796030149853,
          -1.5640179924381026,
          -0.13688955423625848,
          -1.1610731466206823,
          -1.3290824433491815,
          -0.3246270958735874,
          0.3437755254896022,
          -2.864457425601847,
          -1.8948208629847105,
          -1.6938645452381358,
          -0.5318158154511532,
          -2.0000907340246163,
          -0.06626830908218895,
          -1.3527993167823336,
          -2.3377355820402745,
          -0.7803237510364497,
          -1.7582144896349892,
          -1.6092157966475442,
          -1.7927249405292385,
          -2.044713059673068,
          0.6598082260718543,
          -1.1926306059009752,
          -1.277338651764322,
          -0.21375713112345807,
          -0.30967502523944335,
          -1.8844815712905718,
          2.02621846494838,
          1.171589236461132,
          -2.053018887803619,
          -2.716643177334218,
          -0.10149861778650004,
          -2.2512301011796634,
          -3.560766534294703,
          0.08244860307210722,
          -0.25142562517562717,
          -2.6825550344029954,
          -2.1064887362819804,
          -0.10183016690140823,
          -0.8736727937029706,
          -0.7230986374307276,
          0.8436698738042514
         ]
        },
        {
         "type": "box",
         "uid": "384c1f52-5545-4246-9a85-b0cf5014b82c",
         "y": [
          2.2327388494534004,
          1.4949731597225588,
          0.1863397381505073,
          1.2804501272443778,
          0.1631807937158296,
          1.1854193357174316,
          1.7777911345525874,
          0.4789401022803894,
          0.04008522644584611,
          0.9522675849880958,
          0.6679994298110067,
          3.4116505483986757,
          2.3527855402020856,
          -0.20031827014194126,
          1.6769834969019253,
          -0.17198112053830794,
          1.0770536400008102,
          1.6960097546441817,
          0.30460360330583014,
          1.3393886822862964,
          0.5835426301080062,
          1.1059961581193185,
          0.3417313016878232,
          -1.0011460196929094,
          1.2130904781284846,
          0.47399656400882073,
          1.8296370082952764,
          2.0299501444815258,
          -1.2116659030719834,
          1.2960550443960617,
          0.37310323737815276,
          1.0777778006151988,
          0.037727374339007747,
          0.20754632946522045,
          -0.017922661831740738,
          0.7291639079136525,
          0.5266231447820819,
          -0.2389299417866262,
          -0.4397617296212337,
          0.8028355506386484,
          1.877589305094331,
          1.5152862057524252,
          1.1291858153561836,
          1.6149303371121788,
          0.9628311089754725,
          -0.33668323927393984,
          0.5044340531019385,
          1.2700725299302593,
          1.146818967496132,
          3.985924004729327
         ]
        }
       ],
       "layout": {}
      },
      "text/html": [
       "<div>\n",
       "        \n",
       "        \n",
       "            <div id=\"464b5291-363b-456b-9372-16fc1347ef80\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>\n",
       "            <script type=\"text/javascript\">\n",
       "                require([\"plotly\"], function(Plotly) {\n",
       "                    window.PLOTLYENV=window.PLOTLYENV || {};\n",
       "                    window.PLOTLYENV.BASE_URL='https://plot.ly';\n",
       "                    \n",
       "                if (document.getElementById(\"464b5291-363b-456b-9372-16fc1347ef80\")) {\n",
       "                    Plotly.newPlot(\n",
       "                        '464b5291-363b-456b-9372-16fc1347ef80',\n",
       "                        [{\"type\": \"box\", \"uid\": \"5670fa7c-595e-49f6-b0bb-078dd333754d\", \"y\": [-0.44215510218052356, -1.962751938763073, -1.5955035733628005, -2.3925031703948116, -0.7578744719890991, -1.442432564380551, -1.7231288113182066, -1.0926302184245615, -2.3611279465481214, -1.7151796030149853, -1.5640179924381026, -0.13688955423625848, -1.1610731466206823, -1.3290824433491815, -0.3246270958735874, 0.3437755254896022, -2.864457425601847, -1.8948208629847105, -1.6938645452381358, -0.5318158154511532, -2.0000907340246163, -0.06626830908218895, -1.3527993167823336, -2.3377355820402745, -0.7803237510364497, -1.7582144896349892, -1.6092157966475442, -1.7927249405292385, -2.044713059673068, 0.6598082260718543, -1.1926306059009752, -1.277338651764322, -0.21375713112345807, -0.30967502523944335, -1.8844815712905718, 2.02621846494838, 1.171589236461132, -2.053018887803619, -2.716643177334218, -0.10149861778650004, -2.2512301011796634, -3.560766534294703, 0.08244860307210722, -0.25142562517562717, -2.6825550344029954, -2.1064887362819804, -0.10183016690140823, -0.8736727937029706, -0.7230986374307276, 0.8436698738042514]}, {\"type\": \"box\", \"uid\": \"384c1f52-5545-4246-9a85-b0cf5014b82c\", \"y\": [2.2327388494534004, 1.4949731597225588, 0.1863397381505073, 1.2804501272443778, 0.1631807937158296, 1.1854193357174316, 1.7777911345525874, 0.4789401022803894, 0.04008522644584611, 0.9522675849880958, 0.6679994298110067, 3.4116505483986757, 2.3527855402020856, -0.20031827014194126, 1.6769834969019253, -0.17198112053830794, 1.0770536400008102, 1.6960097546441817, 0.30460360330583014, 1.3393886822862964, 0.5835426301080062, 1.1059961581193185, 0.3417313016878232, -1.0011460196929094, 1.2130904781284846, 0.47399656400882073, 1.8296370082952764, 2.0299501444815258, -1.2116659030719834, 1.2960550443960617, 0.37310323737815276, 1.0777778006151988, 0.037727374339007747, 0.20754632946522045, -0.017922661831740738, 0.7291639079136525, 0.5266231447820819, -0.2389299417866262, -0.4397617296212337, 0.8028355506386484, 1.877589305094331, 1.5152862057524252, 1.1291858153561836, 1.6149303371121788, 0.9628311089754725, -0.33668323927393984, 0.5044340531019385, 1.2700725299302593, 1.146818967496132, 3.985924004729327]}],\n",
       "                        {},\n",
       "                        {\"showLink\": false, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true}\n",
       "                    ).then(function(){\n",
       "                            \n",
       "var gd = document.getElementById('464b5291-363b-456b-9372-16fc1347ef80');\n",
       "var x = new MutationObserver(function (mutations, observer) {{\n",
       "        var display = window.getComputedStyle(gd).display;\n",
       "        if (!display || display === 'none') {{\n",
       "            console.log([gd, 'removed!']);\n",
       "            Plotly.purge(gd);\n",
       "            observer.disconnect();\n",
       "        }}\n",
       "}});\n",
       "\n",
       "// Listen for the removal of the full notebook cells\n",
       "var notebookContainer = gd.closest('#notebook-container');\n",
       "if (notebookContainer) {{\n",
       "    x.observe(notebookContainer, {childList: true});\n",
       "}}\n",
       "\n",
       "// Listen for the clearing of the current output cell\n",
       "var outputEl = gd.closest('.output');\n",
       "if (outputEl) {{\n",
       "    x.observe(outputEl, {childList: true});\n",
       "}}\n",
       "\n",
       "                        })\n",
       "                };\n",
       "                });\n",
       "            </script>\n",
       "        </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "_0 = np.random.randn(50)-1\n",
    "_1 = np.random.randn(50)+1\n",
    "\n",
    "# X轴\n",
    "# trace0 = go.Box(x=_0)\n",
    "# trace1 = go.Box(x=_1)\n",
    "\n",
    "# Y轴\n",
    "trace0 = go.Box(y=_0)\n",
    "trace1 = go.Box(y=_1)\n",
    "\n",
    "data = [trace0, trace1]\n",
    "plotly.offline.iplot(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Grouped Box Plots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "linkText": "Export to plot.ly",
        "plotlyServerURL": "https://plot.ly",
        "showLink": false
       },
       "data": [
        {
         "marker": {
          "color": "#3D9970"
         },
         "name": "kale",
         "type": "box",
         "uid": "c90f914c-3b6f-4fc3-9ff5-812bb48f668a",
         "x": [
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2"
         ],
         "y": [
          0.2,
          0.2,
          0.6,
          1,
          0.5,
          0.4,
          0.2,
          0.7,
          0.9,
          0.1,
          0.5,
          0.3
         ]
        },
        {
         "marker": {
          "color": "#FF4136"
         },
         "name": "radishes",
         "type": "box",
         "uid": "4994f84e-c864-459c-b276-c084e0d3398a",
         "x": [
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2"
         ],
         "y": [
          0.6,
          0.7,
          0.3,
          0.6,
          0,
          0.5,
          0.7,
          0.9,
          0.5,
          0.8,
          0.7,
          0.2
         ]
        },
        {
         "marker": {
          "color": "#FF851B"
         },
         "name": "carrots",
         "type": "box",
         "uid": "c59b437c-1d7a-45de-ad32-86bef62ab906",
         "x": [
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2"
         ],
         "y": [
          0.1,
          0.3,
          0.1,
          0.9,
          0.6,
          0.6,
          0.9,
          1,
          0.3,
          0.6,
          0.8,
          0.5
         ]
        }
       ],
       "layout": {
        "boxmode": "group",
        "yaxis": {
         "title": {
          "text": "normalized moisture"
         },
         "zeroline": false
        }
       }
      },
      "text/html": [
       "<div>\n",
       "        \n",
       "        \n",
       "            <div id=\"4505444c-b3e7-40e3-9db7-e7f6a8c3801c\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>\n",
       "            <script type=\"text/javascript\">\n",
       "                require([\"plotly\"], function(Plotly) {\n",
       "                    window.PLOTLYENV=window.PLOTLYENV || {};\n",
       "                    window.PLOTLYENV.BASE_URL='https://plot.ly';\n",
       "                    \n",
       "                if (document.getElementById(\"4505444c-b3e7-40e3-9db7-e7f6a8c3801c\")) {\n",
       "                    Plotly.newPlot(\n",
       "                        '4505444c-b3e7-40e3-9db7-e7f6a8c3801c',\n",
       "                        [{\"marker\": {\"color\": \"#3D9970\"}, \"name\": \"kale\", \"type\": \"box\", \"uid\": \"c90f914c-3b6f-4fc3-9ff5-812bb48f668a\", \"x\": [\"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\"], \"y\": [0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3]}, {\"marker\": {\"color\": \"#FF4136\"}, \"name\": \"radishes\", \"type\": \"box\", \"uid\": \"4994f84e-c864-459c-b276-c084e0d3398a\", \"x\": [\"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\"], \"y\": [0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2]}, {\"marker\": {\"color\": \"#FF851B\"}, \"name\": \"carrots\", \"type\": \"box\", \"uid\": \"c59b437c-1d7a-45de-ad32-86bef62ab906\", \"x\": [\"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\"], \"y\": [0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1.0, 0.3, 0.6, 0.8, 0.5]}],\n",
       "                        {\"boxmode\": \"group\", \"yaxis\": {\"title\": {\"text\": \"normalized moisture\"}, \"zeroline\": false}},\n",
       "                        {\"showLink\": false, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true}\n",
       "                    ).then(function(){\n",
       "                            \n",
       "var gd = document.getElementById('4505444c-b3e7-40e3-9db7-e7f6a8c3801c');\n",
       "var x = new MutationObserver(function (mutations, observer) {{\n",
       "        var display = window.getComputedStyle(gd).display;\n",
       "        if (!display || display === 'none') {{\n",
       "            console.log([gd, 'removed!']);\n",
       "            Plotly.purge(gd);\n",
       "            observer.disconnect();\n",
       "        }}\n",
       "}});\n",
       "\n",
       "// Listen for the removal of the full notebook cells\n",
       "var notebookContainer = gd.closest('#notebook-container');\n",
       "if (notebookContainer) {{\n",
       "    x.observe(notebookContainer, {childList: true});\n",
       "}}\n",
       "\n",
       "// Listen for the clearing of the current output cell\n",
       "var outputEl = gd.closest('.output');\n",
       "if (outputEl) {{\n",
       "    x.observe(outputEl, {childList: true});\n",
       "}}\n",
       "\n",
       "                        })\n",
       "                };\n",
       "                });\n",
       "            </script>\n",
       "        </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2']\n",
    "\n",
    "trace0 = go.Box(\n",
    "    y=[0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3],\n",
    "    x=x,\n",
    "    name='kale',\n",
    "    marker=dict(color='#3D9970')\n",
    ")\n",
    "trace1 = go.Box(\n",
    "    y=[0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2],\n",
    "    x=x,\n",
    "    name='radishes',\n",
    "    marker=dict(color='#FF4136')\n",
    ")\n",
    "trace2 = go.Box(\n",
    "    y=[0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1.0, 0.3, 0.6, 0.8, 0.5],\n",
    "    x=x,\n",
    "    name='carrots',\n",
    "    marker=dict(color='#FF851B')\n",
    ")\n",
    "\n",
    "data = [trace0, trace1, trace2]\n",
    "layout = go.Layout(\n",
    "    yaxis=dict(\n",
    "        title='normalized moisture',\n",
    "        zeroline=False\n",
    "    ),\n",
    "    boxmode='group'\n",
    ")\n",
    "fig = go.Figure(data=data, layout=layout)\n",
    "plotly.offline.iplot(fig)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
